<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <?php
    if (isset($_POST['tags'])) {
        $tags = explode(", ", $_POST['tags']);
        $tagsFrequency = array();

        $result = '<div>';

        foreach ($tags as $tag) {
            if (isset($tagsFrequency[$tag])) {
                $tagsFrequency[$tag]++;
            }
            else {
                $tagsFrequency[$tag] = 1;
            }
        }

        arsort($tagsFrequency);
        $counter = 1;

        foreach ($tagsFrequency as $key => $val) {
            $result .= '<div>' . $counter . ". " . htmlspecialchars($key) . " - " . $val;

            if ($val !== 1) {
                $result .= " times";
            }
            else {
                $result .= " time";
            }

            $result .= "</div>";

            $counter++;
        }

        $keys = array_keys($tagsFrequency);
        $mostFrequent = $tagsFrequency[$keys[0]];

        $result .= '<div>' . "Most frequent number is: $tagsFrequency[$mostFrequent]</div></div>";
    }
    ?>
</head>
<body>
<div>Enter tags:</div>
<form action="most-frequent-element.php" method="post">
    <input type="text" name="tags">
    <input type="submit" name="submit" value="Submit">
</form>
<?php
if (isset($result)) {
    echo $result;
}
?>
</body>
</html>